<template>
  <div class="group">
    <h3 class="group-title">
      租房小组
      <span class="more">更多</span>
    </h3>
    <van-grid
      class="group-grid"
      direction="horizontal"
      :column-num="2"
      :gutter="10"
      :clickable="true"
    >
      <van-grid-item v-for="item in groups" :key="item.id">
        <img class="imgs" slot="icon" :src="imgBaseURL + item.imgSrc" alt="" />
        <div slot="text">
          <span class="title">{{ item.title }}</span>
          <span class="desc">{{ item.desc }}</span>
        </div>
      </van-grid-item>
    </van-grid>
  </div>
</template>

<script>
import { mapState } from 'vuex'
import { homeGroupsAPI } from '@/api'
export default {
  name: 'RentGroup',
  data() {
    return {
      groups: [],
      imgBaseURL: 'http://liufusong.top:8080'
    }
  },
  computed: {
    ...mapState(['myCity'])
  },
  created() {
    this.homeGroups()
  },
  methods: {
    // 获取租房小组
    async homeGroups() {
      const data = await homeGroupsAPI(this.myCity.value)
      this.groups = data.body
    }
  }
}
</script>

<style scoped lang="less">
// 租房小组
.group {
  background-color: #f6f5f6;
  overflow: hidden;
  padding-bottom: 10px;
  .group-title {
    position: relative;
    margin: 15px 10px 15px 20px;
    font-size: 15px;
    line-height: 17.5px;
    .more {
      color: #787d82;
      position: absolute;
      right: 0;
      font-size: 14px;
      font-weight: 400;
    }
  }
  .group-grid {
    .van-grid-item__content {
      padding: unset;
      margin-bottom: 10px;
      justify-content: start;
    }
    .imgs {
      height: 50px;
      width: 50px;
      margin: 0 10px;
    }
    .title {
      display: block;
      font-size: 14px;
      color: #333;
    }
    .desc {
      display: block;
      font-size: 12px;
      color: #888;
    }
  }
}
</style>
